package com.ruoyi.app.controller.project;

import com.ruoyi.app.business.project.ProjectSuddenBusiness;
import com.ruoyi.app.domain.project.sudden.ProjectSudden;
import com.ruoyi.app.domain.project.sudden.ProjectSuddenSave;
import com.ruoyi.common.core.utils.CommonUtils;
import com.ruoyi.common.core.web.domain.APIResult;
import com.ruoyi.common.core.web.page.CommonPageInfo;
import com.ruoyi.common.core.web.page.TableDataInfo;
import com.ruoyi.service.project.query.ProjectSuddenBaseQuery;
import javax.annotation.Resource;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

/**
 * 项目异常管理
 *
 * @author Zane
 * @since 2025-10-10
 */
@RestController
@RequestMapping("/project/sudden/")
public class ProjectSuddenController {

  @Resource
  private ProjectSuddenBusiness projectSuddenBusiness;

  /**
   * 项目异常列表
   */
  @PostMapping("/list")
  public TableDataInfo<ProjectSudden> list(
      @Validated @RequestBody ProjectSuddenBaseQuery suddenQuery) {
    CommonPageInfo<ProjectSudden> suddenPage = projectSuddenBusiness.list(suddenQuery);
    return CommonUtils.buildTableData(suddenPage);
  }

  /**
   *  异常详情
   * @param id 异常ID
   */
  @GetMapping("/detail")
  public APIResult<ProjectSudden> detail(@RequestParam("id") Long id) {
    ProjectSudden projectSudden =projectSuddenBusiness.detail(id);
    return APIResult.success(projectSudden);
  }
  /**
   * 项目异常保存(新增和修改)
   */
  @PostMapping("/save")
  public APIResult<Void> save(@Validated @RequestBody ProjectSuddenSave suddenSave) {
      projectSuddenBusiness.save(suddenSave);
    return APIResult.success();
  }
  /**
   * 项目异常删除
   * @param id 异常ID
   */
  @PostMapping("/delete")
  public APIResult<Void> delete(@RequestParam("id") Long id) {
    projectSuddenBusiness.delete(id);
    return APIResult.success();
  }

}
